/*
 * Daniel R Padilla
 *
 * Copyright (c) 2007, Daniel R Padilla
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.databasefacade.registry;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import org.databasefacade.table.Table;



public class TableRegistry {
    private ArrayList allTableNames = new ArrayList();
    private ArrayList tables = new ArrayList();
    private HashMap tablesMap = new HashMap();

    
    public void registerTable(Table table) {
        tables.add(table);
        tablesMap.put(table.getTableName().toUpperCase(), table);
        allTableNames.add(table.getTableName().toUpperCase());
    }
    
    public int size() {
        return tables.size();
    }

    public Iterator getTables() {
        return tables.iterator();
    }

    public Table getRegisteredTable(String name) {
        return (Table) tablesMap.get(name.toUpperCase());
    }
    
    public Table getTable(int i) {
        if (i >= 0 && i < tables.size()) {
            Table table = (Table) tables.get(i);
            return table.getCopy();
        } else {
            return null;
        }
    }
    
}
